"""MobileNet-V2 Utils."""

from typing import Optional


def make_divisible(v: float,
                   divisor: int,
                   min_value: Optional[int] = None
                   ) -> int:
    """
    It ensures that all layers have a channel number that is divisible by 8.

    Args:
        v (int): original channel of kernel.
        divisor (int): Divisor of the original channel.
        min_value (int, optional): Minimum number of channels.

    Returns:
        Number of channel.

    Examples:
        >>> _make_divisible(32, 8)
    """

    if not min_value:
        min_value = divisor
    new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
    # Make sure that round down does not go down by more than 10%.
    if new_v < 0.9 * v:
        new_v += divisor
    return new_v
